package com.cn.aam.checaiduo.ui.me.fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.baoyz.widget.PullRefreshLayout;
import com.cn.aam.checaiduo.R;
import com.cn.aam.checaiduo.base.BaseFragment;
import com.cn.aam.checaiduo.bean.me.VoucherB;
import com.cn.aam.checaiduo.ui.me.adapter.VoucherAdapter;
import com.cn.aam.checaiduo.widget.MultiStateView;

import butterknife.BindView;

/**
 * monker on 2017/5/25.
 * 代金券
 */

public class VoucherFragment extends BaseFragment {

    public static final int RATE_COUPON = 1;//加息券
    public static final int CASH_COUPON = 2;//代金券

    @BindView(R.id.id_recyclerview)
    RecyclerView idRecyclerview;
    @BindView(R.id.id_multistateview)
    MultiStateView idMultistateview;
    @BindView(R.id.id_swipe)
    PullRefreshLayout idSwipe;

    private VoucherB mVoucherB;
    private int type;

    public static VoucherFragment newInstance(VoucherB voucherB, int type) {
        VoucherFragment intance = new VoucherFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("bean", voucherB);
        bundle.putInt("type", type);
        intance.setArguments(bundle);
        return intance;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.content_universal_normal_recyclerview;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        mVoucherB = (VoucherB) getArguments().getSerializable("bean");
        type = getArguments().getInt("type");
        idSwipe.setEnabled(false);
        idMultistateview.setViewForState(R.layout.content_list_state_empty1, MultiStateView.VIEW_STATE_EMPTY);
        if (type == CASH_COUPON) {
            idMultistateview.setViewState((mVoucherB == null || mVoucherB.getCash_coupon().size() == 0)
                    ? MultiStateView.VIEW_STATE_EMPTY : MultiStateView.VIEW_STATE_CONTENT);
        } else if (type == RATE_COUPON) {
            idMultistateview.setViewState((mVoucherB == null || mVoucherB.getRate_coupon().size() == 0)
                    ? MultiStateView.VIEW_STATE_EMPTY : MultiStateView.VIEW_STATE_CONTENT);
        }

        if (mVoucherB == null) return;
        LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
        VoucherAdapter adapter = new VoucherAdapter(mActivity, mVoucherB, type);
        idRecyclerview.setLayoutManager(layoutManager);
        idRecyclerview.setAdapter(adapter);
    }

}
